package org.gap.jseed.contract;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.gap.jseed.contract.annotation.Condition;
import org.gap.jseed.contract.annotation.Require;
import org.gap.jseed.injection.ClassWriter;

public class RequireValidation extends ValidationWriter {

	@Override
	public void injectBehavior(ClassWriter javaWriter, Method method, Annotation annotation) {
		Require pre = (Require)annotation;
		StringBuffer preConditions = new StringBuffer();
		for (Condition each : pre.value()) {
			String preCondition = createTestCondition(each.value()) + createPreConditionViolationException(each);
			preConditions.append(preCondition);
		}
		javaWriter.insertBefore(method, preConditions.toString());
	}
}
